package com.funtl.spring.cloud.alibaba.unit.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @ClassName RedisKeyResolver
 * @Description TODO
 * @Author Mr.Starry
 * @Date 2019/12/24 21:15
 * @Version 1.0
 */
@Component
public class RedisKeyResolver implements KeyResolver {
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        // exchange.getRequest().getRemoteAddress().getAddress().getHostAddress()是获取ip地址
        // mono.just方法是将字符串返回。
        return Mono.just(
                exchange.getRequest().getRemoteAddress().getAddress().getHostAddress()
        );
    }
}
